/*
 * EnemyFactory.cs
 *
 * Created on November 25, 2007, 2:19 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * Copyright (C) 2010       Mathijs Miermans
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

using System.Windows.Media;
using System.Windows.Shapes;
using System.Collections.Generic;

using HexTD.util;

namespace HexTD.sprite
{
	public class EnemyFactory
	{
		public class Enemy
		{
#if PORT
			BlueBox         ("bb", new ESBlueBox()),
			FastForward     ("ff", new ESFastForward()),
			GreenPlus       ("gp", new ESGreenPlus()),
			HardGrey        ("hg", new ESHardGrey()),
			HealthyHelix    ("hh", new ESHealthyHelix()),
			PeachyPinata    ("pep", new ESPeachyPinata()),
			ProtectedPink   ("prp", new ESProtectedPink()),
			RedRaver        ("rr", new ESRedRaver()),
			SprintingSalmon("ss", new ESSprintingSalmon()),
			YellorRotor     ("yr", new ESYellowRotor());
#endif

			private string name;
			private EnemySprite instance;
			Enemy(string name, EnemySprite instance)
			{
				this.name = name;
				this.instance = instance;
			}
			public string getName()
			{
				return this.name;
			}
			public float getPreferredDelay()
			{
				return this.instance.getPreferredDelay();
			}
			public EnemySprite getCopy(Context context, int path, float delay, long health, int price, Size s)
			{
				return instance.create(context, path, delay, health, price, s);
			}
		}

		private static Dictionary<string, Enemy> table = new Dictionary<string, Enemy>();

		static EnemyFactory()
		{
#if PORT
			foreach (Enemy enemy in Enemy.values())
			{
				table.put(enemy.getName(), enemy);
			}
#endif
		}

		public static bool isEnemy(string name)
		{
			return table.ContainsKey(getNamePart(name));
		}

		public static Enemy identifyEnemy(string name)
		{
			return table[getNamePart(name)];
		}

		public static EnemySprite getEnemy(string name, Context context, int path, float delay, long health, int price)
		{
			return table[getNamePart(name)].getCopy(context, path, delay, health, price, getSize(name));
		}

		public static string getNamePart(string name)
		{
			switch (name[0])
			{
				case 'L':
				case 'S':
				case 'N':
					return name.Substring(1);
				default:
					return name;
			}
		}

		public static Size getSize(string name)
		{
			switch (name[0])
			{
				case 'L':
					return Size.large;
				case 'S':
					return Size.small;
				case 'N':
				default:
					return Size.normal;
			}
		}
	}
}